<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/* Start of file tax.php */
/* Location: ./cashflow/controllers/tax.php */
class Tax extends CI_Controller {
	
	function __construct(){
		parent::__construct();
		$this->load->model('taxs'); /** load table taxs **/
        if(!$this->session->userdata('username')) /** restrict area if not acces to login page**/
			redirect('/',301); 
    }
    
    function pph21(){
        $this->ws->set('title',lang('pph21_tax'));/** title page pph 21 tax */
		$this->ws->set('username',$this->session->userdata('username')); /** username session */
		$this->ws->set('department',$this->session->userdata('dep')); /** departement session */
        /** if tax session already or no to view data **/
        if($this->session->userdata('tax21_start')):
            $date_start  =   $this->session->userdata('tax21_start');
            $date_end    =   $this->session->userdata('tax21_end');
        else:
            $date_start  =   '-';
            $date_end    =   '-';
        endif;
        $this->ws->set('date_start',$date_start); /** variabel date start from session **/
        $this->ws->set('date_end',$date_end); /** variabel date end from session **/   
        $this->ws->set('taxs',$this->taxs->getTaxBudget('Pasal 21',$date_start,$date_end)); /** Get Data Table pdo Budget */
        $this->ws->set_theme('smooth'); /** set theme to smooth **/
		$this->ws->view('tax/index_pph21'); /** view layout to views/bank/index_summary*/
    }
    
    function getTaxPPH21(){
        /** array : insert value session from post **/
        $value  = array('tax21_start'=> $this->input->post('year').'-'.$this->input->post('month').'-'.$this->input->post('day'),
                        'tax21_end'  => $this->input->post('year2').'-'.$this->input->post('month2').'-'.$this->input->post('day2'));
        $this->session->set_userdata($value); /** set userdata value **/
        redirect('cashflow/tax/pph21',301); /** redirect to summary **/
    }
    
    function getTaxPPH21Export(){  
        /** if export via excel **/    
		if($this->input->post('export')=='excel')
            redirect('cashflow/tax/getTaxPPH21Excel/'); 
        /** if export via pdf **/    
        elseif($this->input->post('export')=='pdf')    
            redirect('cashflow/tax/getTaxPPH21Pdf/');
        /** if export via email **/  
        elseif($this->input->post('export')=='email')    
            redirect('cashflow/tax/getTaxPPH21Email');
		else
			echo 'Error redirecting'; /** if error redirecting the page **/
    }
    
    function getTaxPPH21Excel(){
        /** Session Variabel **/
        $date_start =   $this->session->userdata('tax21_start');
        $date_end   =   $this->session->userdata('tax21_end');
       	$excel      =   $this->taxs->getExcelTaxPPH21('Pasal 21',$date_start,$date_end); /** file */
        $value      =   file_get_contents($excel); /** Read the file's contents **/
        $name       =   'PPH-21.xls'; /** file name content **/
        force_download($name,$value); /** download the file **/
    }
    
    function getTaxPPH21Pdf(){
        /** Session Variabel **/
        $date_start =   $this->session->userdata('tax21_start');
        $date_end   =   $this->session->userdata('tax21_end');
       	$pdf        =   $this->taxs->getPdfTaxPPH21('Pasal 21',$date_start,$date_end); /** file */
        $value      =   file_get_contents($pdf); /** Read the file's contents **/
        $name       =   'PPH-21.pdf'; /** file name content **/
        force_download($name,$value); /** download the file **/
    }
    
    
    function getTaxPPH21Email(){
       /** Session Variabel **/
        $date_start =   $this->session->userdata('tax21_start');
        $date_end   =   $this->session->userdata('tax21_end');
        $excel      =   $this->taxs->getExcelTaxPPH21('Pasal 21',$date_start,$date_end); /** file */
        /** email configuration **/
        $mail_config    =   $this->config->item('mail');
        $smtp_host      =   $mail_config['smtp_host'];
        $smtp_port      =   $mail_config['smtp_port'];
        $from_mail      =   $mail_config['from_mail'];
        $from_name      =   $mail_config['from_name'];
        
        /** php ini set email **/
        ini_set("SMTP",$smtp_host);
        ini_set("smtp_port",$smtp_port);
        ini_set('sendmail_from',$from_mail);
        /** Properties of export **/
        $subject        = 'BBG SAF PPH 21'.indonesian_date($date_start)." Sampai ". indonesian_date($date_end);
        $contents       = 'Dilampirkan PPH 21'.indonesian_date($date_start)." Sampai ". indonesian_date($date_end);
        $this->email->initialize($mail_config);
        $this->email->from($from_mail,$from_name);
        $email  =   'hendarsyahss@gmail.com';
        $this->email->to($email); /** email to */
        $this->email->subject($subject); /** email subject */
        $this->email->message($contents); /** email content */
        $this->email->attach($excel);  /** email attachement */
        $d=$this->email->send(); /** email send */
        if(!$d):
            $this->session->set_flashdata('error','error');
        else:
			$this->session->set_flashdata('success','success');
        endif;
        redirect('cashflow/tax/pph21',301);
    }
   
    function getTaxPPH21Reset(){
        /** array : delete from value session **/
        $value  = array('tax21_start'=> 'tax21_start',
                        'tax21_end'  => 'tax21_end');
        $this->session->unset_userdata($value); /** set userdata value **/
        redirect('cashflow/tax/pph21',301); /** redirect to php21 **/
    }
    
    function pph23(){
        $this->ws->set('title',lang('pph23_tax'));/** title page pph 23 tax */
		$this->ws->set('username',$this->session->userdata('username')); /** username session */
		$this->ws->set('department',$this->session->userdata('dep')); /** departement session */
        /** if tax session already or no to view data **/
        if($this->session->userdata('tax23_start')):
            $date_start  =   $this->session->userdata('tax23_start');
            $date_end    =   $this->session->userdata('tax23_end');
        else:
            $date_start  =   '-';
            $date_end    =   '-';
        endif;
        $this->ws->set('date_start',$date_start); /** variabel date start from session **/
        $this->ws->set('date_end',$date_end); /** variabel date end from session **/   
        $this->ws->set('taxs',$this->taxs->getTaxBudget('Pasal 23',$date_start,$date_end)); /** Get Data Table pdo Budget */
        $this->ws->set_theme('smooth'); /** set theme to smooth **/
		$this->ws->view('tax/index_pph23'); /** view layout to views/bank/index_pph23*/
    }
    
    function getTaxPPH23(){
        /** array : insert value session from post **/
        $value  = array('tax23_start'=> $this->input->post('year').'-'.$this->input->post('month').'-'.$this->input->post('day'),
                        'tax23_end'  => $this->input->post('year2').'-'.$this->input->post('month2').'-'.$this->input->post('day2'));
        $this->session->set_userdata($value); /** set userdata value **/
        redirect('cashflow/tax/pph23',301); /** redirect to summary **/
    }
    
    function getTaxPPH23Export(){  
        /** if export via excel **/    
		if($this->input->post('export')=='excel')
            redirect('cashflow/tax/getTaxPPH23Excel/'); 
        /** if export via pdf **/    
        elseif($this->input->post('export')=='pdf')    
            redirect('cashflow/tax/getTaxPPH23Pdf/');
        /** if export via email **/  
        elseif($this->input->post('export')=='email')    
            redirect('cashflow/tax/getTaxPPH23Email');
		else
			echo 'Error redirecting'; /** if error redirecting the page **/
    }
    
    function getTaxPPH23Excel(){
        /** Session Variabel **/
        $date_start =   $this->session->userdata('tax23_start');
        $date_end   =   $this->session->userdata('tax23_end');
       	$excel      =   $this->taxs->getExcelTaxPPH23('Pasal 23',$date_start,$date_end); /** file */
        $value      =   file_get_contents($excel); /** Read the file's contents **/
        $name       =   'PPH-23.xls'; /** file name content **/
        force_download($name,$value); /** download the file **/
    }
    
    function getTaxPPH23Email(){
       /** Session Variabel **/
        $date_start =   $this->session->userdata('tax23_start');
        $date_end   =   $this->session->userdata('tax23_end');
        $excel      =   $this->taxs->getExcelTaxPPH23('Pasal 23',$date_start,$date_end); /** file */
        /** email configuration **/
        $mail_config    =   $this->config->item('mail');
        $smtp_host      =   $mail_config['smtp_host'];
        $smtp_port      =   $mail_config['smtp_port'];
        $from_mail      =   $mail_config['from_mail'];
        $from_name      =   $mail_config['from_name'];
        
        /** php ini set email **/
        ini_set("SMTP",$smtp_host);
        ini_set("smtp_port",$smtp_port);
        ini_set('sendmail_from',$from_mail);
        /** Properties of export **/
        $subject        = 'BBG SAF PPH 21'.indonesian_date($date_start)." Sampai ". indonesian_date($date_end);
        $contents       = 'Dilampirkan PPH 21'.indonesian_date($date_start)." Sampai ". indonesian_date($date_end);
        $this->email->initialize($mail_config);
        $this->email->from($from_mail,$from_name);
        $email  =   'hendarsyahss@gmail.com';
        $this->email->to($email); /** email to */
        $this->email->subject($subject); /** email subject */
        $this->email->message($contents); /** email content */
        $this->email->attach($excel);  /** email attachement */
        $d=$this->email->send(); /** email send */
        if(!$d):
            $this->session->set_flashdata('error','error');
        else:
			$this->session->set_flashdata('success','success');
        endif;
        redirect('cashflow/tax/pph23',301);
    }
    
    function getTaxPPH23Pdf(){
        /** Session Variabel **/
        $date_start =   $this->session->userdata('tax23_start');
        $date_end   =   $this->session->userdata('tax23_end');
       	$pdf        =   $this->taxs->getPdfTaxPPH23('Pasal 23',$date_start,$date_end); /** file */
        $value      =   file_get_contents($pdf); /** Read the file's contents **/
        $name       =   'PPH-23.pdf'; /** file name content **/
        force_download($name,$value); /** download the file **/
    }
    
    function getTaxPPH23Reset(){
        /** array : delete from value session **/
        $value  = array('tax23_start'=> 'tax23_start',
                        'tax23_end'  => 'tax23_end');
        $this->session->unset_userdata($value); /** set userdata value **/
        redirect('cashflow/tax/pph23',301); /** redirect to php21 **/
    }
    
    function tax_cuts(){
        $this->ws->set('title',lang('tax_cuts'));/** title page tax cuts  */
		$this->ws->set('username',$this->session->userdata('username')); /** username session */
		$this->ws->set('department',$this->session->userdata('dep')); /** departement session */
        /** if tax session already or no to view data **/
        if($this->session->userdata('taxcuts_start')):
            $date_start  =   $this->session->userdata('taxcuts_start');
            $date_end    =   $this->session->userdata('taxcuts_end');
            $type        =   $this->session->userdata('taxcuts_type');
        else:
            $date_start  =   '-';
            $date_end    =   '-';
            $type        =   '-';
        endif;
        $this->ws->set('date_start',$date_start); /** variabel date start from session **/
        $this->ws->set('date_end',$date_end); /** variabel date end from session **/  
        $this->ws->set('type',$type); /** variabel date end from session **/  
        $this->ws->set('taxtype',$this->taxs->getTaxData()); /** Get Data Table pajak */
        $this->ws->set('taxs',$this->taxs->getTaxBudget($type,$date_start,$date_end)); /** Get Data Table pdo Budget */
        $this->ws->set_theme('smooth'); /** set theme to smooth **/
		$this->ws->view('tax/index_taxcuts'); /** view layout to views/bank/index_summary*/
    }
    
    function getTaxCuts(){
        /** array : insert value session from post **/
        $value  = array('taxcuts_start'=> $this->input->post('year').'-'.$this->input->post('month').'-'.$this->input->post('day'),
                        'taxcuts_end'  => $this->input->post('year2').'-'.$this->input->post('month2').'-'.$this->input->post('day2'),
                        'taxcuts_type' => $this->input->post('type'));
        $this->session->set_userdata($value); /** set userdata value **/
        redirect('cashflow/tax/tax_cuts',301); /** redirect to taxcuts **/
    }
    
    function getTaxCutsReset(){
        /** array : delete from value session **/
        $value  = array('taxcuts_start'=> 'taxcuts_start',
                        'taxcuts_end'  => 'taxcuts_end',
                        'taxcuts_type' => 'taxcuts_type',);
        $this->session->unset_userdata($value); /** set userdata value **/
        redirect('cashflow/tax/tax_cuts',301); /** redirect to php21 **/
    }
    
    function getTaxCutsExport(){  
        /** if export via excel **/    
		if($this->input->post('export')=='excel')
            redirect('cashflow/tax/getTaxCutsExcel/'); 
        /** if export via pdf **/    
        elseif($this->input->post('export')=='pdf')    
            redirect('cashflow/tax/getTaxCutsPdf/');
        /** if export via email **/  
        elseif($this->input->post('export')=='email')    
            redirect('cashflow/tax/getTaxCutsEmail');
		else
			echo 'Error redirecting'; /** if error redirecting the page **/
    }
    
    function getTaxCutsExcel(){
        /** Session Variabel **/
        $date_start =   $this->session->userdata('taxcuts_start');
        $date_end   =   $this->session->userdata('taxcuts_end');
        $type       =   $this->session->userdata('taxcuts_type');
       	$excel      =   $this->taxs->getExcelTaxCuts($type,$date_start,$date_end); /** file */
        $value      =   file_get_contents($excel); /** Read the file's contents **/
        $name       =   'Laporan-Potongan-Pajak '.$type.'.xls'; /** file name content **/
        force_download($name,$value); /** download the file **/
    }
    
    function getTaxCutsEmail(){
       /** Session Variabel **/
        $date_start =   $this->session->userdata('taxcuts_start');
        $date_end   =   $this->session->userdata('taxcuts_end');
        $type       =   $this->session->userdata('taxcuts_type');
        $excel      =   $this->taxs->getExcelTaxPPH23($type,$date_start,$date_end); /** file */
        /** email configuration **/
        $mail_config    =   $this->config->item('mail');
        $smtp_host      =   $mail_config['smtp_host'];
        $smtp_port      =   $mail_config['smtp_port'];
        $from_mail      =   $mail_config['from_mail'];
        $from_name      =   $mail_config['from_name'];
        
        /** php ini set email **/
        ini_set("SMTP",$smtp_host);
        ini_set("smtp_port",$smtp_port);
        ini_set('sendmail_from',$from_mail);
        /** Properties of export **/
        $subject        = 'BBG SAF Laporan Pot Pajak'.$type.' '.indonesian_date($date_start)." Sampai ". indonesian_date($date_end);
        $contents       = 'Dilampirkan Laporan Pot Pajak'.$type.' '.indonesian_date($date_start)." Sampai ". indonesian_date($date_end);
        $this->email->initialize($mail_config);
        $this->email->from($from_mail,$from_name);
        $email  =   'hendarsyahss@gmail.com';
        $this->email->to($email); /** email to */
        $this->email->subject($subject); /** email subject */
        $this->email->message($contents); /** email content */
        $this->email->attach($excel);  /** email attachement */
        $d=$this->email->send(); /** email send */
        if(!$d):
            $this->session->set_flashdata('error','error');
        else:
			$this->session->set_flashdata('success','success');
        endif;
        redirect('cashflow/tax/tax_cuts',301);
    }
    
    function getTaxCutsPdf(){
        /** Session Variabel **/
        $date_start =   $this->session->userdata('taxcuts_start');
        $date_end   =   $this->session->userdata('taxcuts_end');
        $type       =   $this->session->userdata('taxcuts_type');
       	$pdf        =   $this->taxs->getPdfTaxCuts($type,$date_start,$date_end); /** file */
        $value      =   file_get_contents($pdf); /** Read the file's contents **/
        $name       =   'Laporan-Potongan '.$type.'.pdf'; /** file name content **/
        force_download($name,$value); /** download the file **/
    }
    
    
}    
    